import java.util.ArrayList;
import java.util.HashMap;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 晓星航
 * Date: 2023-05-13
 * Time: 19:24
 */
interface MoreParameterNoReturn {
    int test(int a, double b);
}
//有返回值无参数
@FunctionalInterface
interface NoParameterReturn {
    int test();
}
//有返回值有一个参数
@FunctionalInterface
interface OneParameterReturn {
    int test(int a);
}
//有返回值有一个参数
@FunctionalInterface
interface MoreParameterReturn {
    int test(int a,int b);
}
public class TestDemo {
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        list.add("Hello");
        list.add("bit");
        list.add("hello");
        list.add("lambda");
//调用带有2个参数的方法，且返回长度的差值
        list.sort((str1,str2)-> str1.length()-str2.length());
        System.out.println(list);
    }
    public static void main5(String[] args) {
        HashMap<Integer, String> map = new HashMap<>();
        map.put(1, "hello");
        map.put(2, "bit");
        map.put(3, "hello");
        map.put(4, "lambda");
        map.forEach((k,v)-> System.out.println(k + "=" + v));
    }
    public static void main4(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        list.add("Hello");
        list.add("bit");
        list.add("hello");
        list.add("lambda");
//表示调用一个，不带有参数的方法，其执行花括号内的语句，为原来的函数体内容。
        list.forEach(s -> {
            System.out.println(s);
        });
    }
    public static void main3(String[] args) {
        MoreParameterNoReturn moreParameterNoReturn = (x,y) -> (int) (x*y);
        int ret = moreParameterNoReturn.test(10,20);
        System.out.println(ret);
    }
    public static void main2(String[] args) {
        OneParameterReturn oneParameterReturn = x -> {return x+10;};
        int ret = oneParameterReturn.test(9);
        System.out.println(ret);
    }
    public static void main1(String[] args) {
        //可以省略return
        NoParameterReturn noParameterReturn = ()->10;
        int ret = noParameterReturn.test();
        System.out.println(ret);
    }
}
